import http from '@/api/http'
import type {
  Active,
  ActiveListData,
  CreateAdminActiveDto,
  UpdateAdminActiveDto,
  ActiveIdData,
  BindActiveDrawDto,
  UpdateActiveDrawDto,
} from '@/types/active.api'

// 活动中心 API
export const listActives = (params?: {
  name?: string
  status?: string
  progress?: string
  page?: number
  size?: number
}): Promise<ApiResponse<ActiveListData>> => {
  return http.get<ActiveListData>('/admin/active', { params })
}

export const getActiveDetail = (id: string): Promise<ApiResponse<Active>> => {
  return http.get<Active>(`/admin/active/${id}`)
}

export const createActive = (
  dto: CreateAdminActiveDto,
): Promise<ApiResponse<ActiveIdData>> => {
  // 按照 api.json：POST /admin/active 创建活动
  return http.post<CreateAdminActiveDto, ActiveIdData>('/admin/active', dto)
}

export const updateActive = (
  id: string,
  dto: UpdateAdminActiveDto,
): Promise<ApiResponse<ActiveIdData>> => {
  return http.patch<UpdateAdminActiveDto, ActiveIdData>(`/admin/active/${id}`, dto)
}

export const deleteActive = (id: string): Promise<ApiResponse<ActiveIdData>> => {
  return http.del<ActiveIdData>(`/admin/active/${id}`)
}

export const bindActiveDraw = (
  id: string,
  dto: BindActiveDrawDto,
): Promise<ApiResponse<ActiveIdData>> => {
  return http.post<BindActiveDrawDto, ActiveIdData>(`/admin/active/${id}/draws`, dto)
}

// 更新活动-奖品关联配置（与文档 /admin/active/{id}/draws/{drawId} 对齐）
export const updateActiveDrawConfig = (
  id: string,
  drawId: string,
  dto: UpdateActiveDrawDto,
): Promise<ApiResponse<ActiveIdData>> => {
  return http.patch<UpdateActiveDrawDto, ActiveIdData>(`/admin/active/${id}/draws/${drawId}`, dto)
}
